﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using NUnit.Framework;

namespace TypedROBIN.Imaging
{
    [TestFixture]
    public class TestCase
    {
        private string outputDir = null;
        private string ext = ".png";

        [SetUp]
        public void Init()
        {
            outputDir = Directory.GetParent(System.Environment.CurrentDirectory).Parent.Parent.Parent.FullName + @"\temp\";
        }

        [STAThread]
        [Test]
        public void t001_Yahoo()
        {
            string url = @"http://tw.yahoo.com/";
            IECapt iec = new IECapt();
            iec.OnComplete += new IECapt.CompleteEventHandler(iec_OnComplete);
            iec.OnError += new IECapt.ErrorEventHandler(iec_OnError);
            iec.Execute(url, outputDir + @"yahoo480" + ext, 640, 90000, 1000);
            iec.Execute(url, outputDir + @"yahoo800" + ext, 800, 90000, 1000);
            iec.Execute(url, outputDir + @"yahoo1024" + ext, 1024, 90000, 1000);
            iec.Execute(url, outputDir + @"yahoo2048" + ext, 1280, 90000, 1000);

            Thumbnail tb = new Thumbnail();
            tb.Generate(outputDir + @"yahoo480" + ext, outputDir + @"yahoo480t" + ext, 180, 135);
        }

        [STAThread]
        [Test]
        public void t002_Error()
        {
            string url = @"http://tww.yahoo.com/";
            IECapt iec = new IECapt();
            iec.OnComplete += new IECapt.CompleteEventHandler(iec_OnComplete);
            iec.OnError += new IECapt.ErrorEventHandler(iec_OnError);
            iec.Execute(url, outputDir + @"error" + ext);
        }

        void iec_OnError(object sender, ErrorEventArgs e)
        {
            Console.WriteLine("\t錯誤>>>");
            Console.WriteLine("\t\t網頁: " + e.Url);
            Console.WriteLine("\t\t錯誤代碼: " + e.StatusCode);
            Console.WriteLine("\t\t執行: " + e.ExecutionTime + " 毫秒");
        }

        void iec_OnComplete(object sender, CompleteEventArgs e)
        {
            Console.WriteLine("\t完成>>>");
            Console.WriteLine("\t\t網頁: " + e.Url);
            Console.WriteLine("\t\t檔案: " + e.Output);
            Console.WriteLine("\t\t大小: " + e.Size + " 位元組");
            Console.WriteLine("\t\t延遲: " + e.Delay + " 毫秒");
            Console.WriteLine("\t\t執行: " + e.ExecutionTime + " 毫秒");
        }
    }
}
